//
//  NewHomeSectionHeaderView.m
//  NewPro
//
//  Created by RYX on 2019/4/25.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "NewHomeSectionHeaderView.h"
#import "HomeList.h"
#import "CompanyNewsViewController.h"

@implementation NewHomeSectionHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = UIColor.whiteColor;
        [self setUI];
    }
    return self;
}

- (void)setUI{
    
    UIColor *fontColor = [UIColor colorWithHexString:@"333333"];
    
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = UIColor.orangeColor;
    [self addSubview:line];
    
    UILabel *la2 = [[UILabel alloc] init];
    la2.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 14];
    la2.text = @"行业新闻";
    [self addSubview:la2];
    
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"更多" forState:UIControlStateNormal];
    btn.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Medium" size: 12];
    [btn setTitleColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1.0] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = [UIColor colorWithHexString:@"EBEBEB"];
    [self addSubview:line1];
    
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.top.equalTo(self).offset(14);
        make.width.mas_equalTo(1.5);
        make.height.mas_equalTo(14);
    }];
    
    [la2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(line.mas_right).offset(2);
        make.centerY.equalTo(line);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(self).offset(-14);
        make.centerY.equalTo(line);
    }];
    
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(self).offset(14);
        make.bottom.equalTo(self);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(0.5);
    }];
}

#pragma mark - 更多
- (void)onMoreBtn:(UIButton *)sender{
    
    if (![[HomeList sharedInstance].hadRealName isEqualToString:@"4"]) {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(judgeIfHadRealName)]) {
            
            [self.delegate judgeIfHadRealName];
            return;
        }
        return;
    }
    
    CompanyNewsViewController *VC = [[CompanyNewsViewController alloc] init];
    [VC setHidesBottomBarWhenPushed:YES];
    [[self getCurrentViewController].navigationController pushViewController:VC animated:YES];
}

@end
